home *** CD-ROM | disk | FTP | other *** search
- Path: eccdb1.pms.ford.com!pms991!mbobak
- From: mbobak@pms991.uucp (Mark J. Bobak)
- Newsgroups: comp.lang.c
- Subject: Re: reversing a string
- Date: 10 Apr 1996 14:38:40 GMT
- Organization: Not an Official Spokesperson for Ford Motor Company, Dearborn, MI
- Message-ID: <4kgh5g$1ue@eccdb1.pms.ford.com>
- References: <4k6cjl$j8f@central.server.swt.edu>
- NNTP-Posting-Host: pms991.pms.ford.com
-
- In article <4k6cjl$j8f@central.server.swt.edu>,
- Leland Newsom <ln16674@nyssa.swt.edu> wrote:
- >I have a challenge from a friend of mine. He wanted me to reverse a string
- >with recursion without using any additional variables or loops. I got mine
- >to work by using exclusive or, but I needed an additional variable. Can
- >someone help with this problem without using the additional variable?
- >
- >Thanks
-
-
- Well, here's what I came up with....it seems to work.
-
- #include <stdio.h>
- #include <string.h>
- void revstr(char *string, int position)
- {
- printf("%c",string[position]);
- if(position-1 >= 0)
- revstr(string,position-1);
- }
- main(int argc, char **argv)
- {
- revstr(argv[1],strlen(argv[1]));
- printf("\n");
- }
- --
- Mark J. Bobak, Application Developer
- Advanced Vehicle & Computer Aided Engineering Systems Department
- Process Leadership, Ford Motor Company
- mbobak@ford.com
-